package breadbox.dataManagement;

import java.io.IOException;

import breadbox.pastry.ID;

public class LocalReplicationManager extends ReplicationManager {
	
	LocalManager manager;
	private Storage replicatedStorage;	//create another Storage system to test replication
	
	public void run() {
		//TODO: do something
	}
	
	public LocalReplicationManager(Manager lm) {
		super(lm);
		replicatedStorage = null;
		try {
			replicatedStorage = new DiskStorage("C:\\breadbox2");
		}
		catch(Exception e) {
			System.err.println("could not instantiate replicated storage");
		}
	}
	
	public void replicate(byte[] data, ID id) {
		//in order to test locally, the data is replicated to another storage system
		if(replicatedStorage != null) {
			try {
				replicatedStorage.write(id, data);
			}
			catch(IOException e) { }
		}
	}
	
	public void replicateDelete(ID id) {
		if(replicatedStorage != null) {
			try {
				replicatedStorage.delete(id);
			}
			catch(IOException e) { }
		}
	}
}
